<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.xxfset.js"></script>
<script type="text/javascript">
$.fn.extend({
	xxfile:function(obj){
		var that=this;
		var _obj={
			url:"admin_defaultUp.php",
			accept:"",
			data:{},
			maxsize:2*1024*1024,//Byte
			multiple:false,
			success:function(data){var _k=this.data.get("progressbarID");setTimeout(function(){$("#progressbar_"+_k).hide(2000);},2000);},
			error:function(data){alert(data);}
		};
		$.extend(_obj,obj);
		this[0].accept=_obj.accept||this[0].accept;
		this[0].multiple=_obj.multiple||this[0].multiple;
		this.change(function(){
			$.each(this.files,function(k,v){
				that.after("<div id='progressbar_"+k+"'><div>"+v.name+" <span id='prostatus_"+k+"'>上传中。。。</span></div><div id='progress_"+k+"' style='background-color:red;width:0%;'></div></div>");
				if(v.size<=_obj.maxsize){
					var formdata=new FormData();
					formdata.append("file",v);
					formdata.append("progressbarID",k);
					for(e in _obj.data){
						formdata.append(e,_obj.data[e]);
					}
					$.ajax({
						url:_obj.url,  
						type: 'POST',  
						data: formdata, 
						cache: false,
						contentType: false,  
						processData: false,  
						success:_obj.success,
						error:_obj.error,
						xhr:function() {
							myXhr = $.ajaxSettings.xhr();
							if(myXhr.upload){
								myXhr.upload.addEventListener('progress',function(event){
									if(event.lengthComputable){
										var complete=(event.loaded/event.total*100|0);
										document.getElementById("progress_"+k).innerHTML=complete+"%";
										document.getElementById("progress_"+k).style.width=complete+"%";
										console.log(v.name+complete);
										if(complete==100){
											document.getElementById("prostatus_"+k).innerHTML="完成";
										}
									}
								}, false);
							}
							return myXhr;
						}
					});
				}else{
					
				}
			});
		});
	}
});
</script>
<input id="uppic" type="file" accept="" multiple/>
<button>123</button>
<script>
	$("#uppic").xxfile({
		url:"test",
		maxsize:1024*1024*1024,
		data:{
			type:"upload"
		}
	});
</script>